<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@include file="/WEB-INF/base.jspf"%>
<!DOCTYPE html>
<html>
<head>
<title>跟单控制</title>
<style>
	.div-c-controlBtns {
		display:flex;
		justify-content:flex-end;
		margin-bottom:16px;
	}
	.div-c-controlBtns button + button {
		margin-left:8px;
	}
		.modal-dialog {
		max-width: 1000px;
	}
	.p-c-flexwrapper {
		display:flex;
		align-items:center;
		margin-right:16px;
		margin-bottom:16px;
	}
	.p-c-flexwrapper > span {
		width:80px;
	}
	.p-c-flexwrapper > .form-control {
		width:180px;
	}
	.hidden-td {
		display:none;
	}
	table th,table tr,table td {
text-align: center;
vertical-align:middle;
}
.tuijianfeilv-tr td:nth-child(even) .form-control {
	width:56px;
}
</style>
</head>
<body>
	<div class="div-c-controlBtns" style="justify-content:flex-end;align-items:center;">
		<button class="btn btn-primary" id="button-i-addNewZongDaiLi" style="margin-left:16px;">修改规则</button>
	</div>
		<p style="font-weight:bold;color:red;">请填写 1 以下的推荐费率</p>
		            	<p class="p-c-flexwrapper"><span style="width:auto;margin-right:12px;">选择从第几单开始跟单</span>
			            	<select class="form-control" id="select-i-chooseDayNum">
			            		<option value="1">1</option>
			            		<option value="2">2</option>
			            		<option value="3">3</option>
			            		<option value="4">4</option>
			            		<option value="5">5</option>
			            		<option value="6">6</option>
			            		<option value="7">7</option>
			            		<option value="8">8</option>
			            		<option value="9">9</option>
			            		<option value="10">10</option>
			            	</select>
		            	</p>
		            	<div style="overflow:auto;">
			            	<table style="overflow: auto;" class="table-c-ShengLvAndTuiJianList table table-striped table-bordered table-hover">
			            		<tbody>
			            			<tr class="tuijianfeilv-tr">
			            				<td>1%~10%推荐费率</td>
			            				<td><input data-rebate="1" class="form-control" /></td>
			            				<td>11%~20%推荐费率</td>
			            				<td><input data-rebate="2" class="form-control" /></td>
			            				<td>21%~30%推荐费率</td>
			            				<td><input data-rebate="3" class="form-control" /></td>
			            				<td>31%~40%推荐费率</td>
			            				<td><input data-rebate="4" class="form-control" /></td>
			            				<td>41%~50%推荐费率</td>
			            				<td><input data-rebate="5" class="form-control" /></td>
			            			</tr>
			            			<tr class="tuijianfeilv-tr">
			            				<td>51%~60%推荐费率</td>
			            				<td><input data-rebate="6" class="form-control" /></td>
			            				<td>61%~70%推荐费率</td>
			            				<td><input data-rebate="7" class="form-control" /></td>
			            				<td>71%~80%推荐费率</td>
			            				<td><input data-rebate="8" class="form-control" /></td>
			            				<td>81%~90%推荐费率</td>
			            				<td><input data-rebate="9" class="form-control" /></td>
			            				<td>91%~100%推荐费率</td>
			            				<td><input data-rebate="10" class="form-control" /></td>		  
			            			</tr>
			            		</tbody>
			            	</table>
		            	</div>
<div class="modal fade" id="noticeModal" tabindex="-1" role="dialog" aria-labelledby="noticeModal" aria-hidden="true">
    <div class="modal-dialog class-fake-alert">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body" ></div>
            <div class="modal-footer">	      
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>   
	<script type="text/javascript" src="/js/zhengzeTools.js"></script>
	<script>
/* 	function shengLvItem(shenglv) {
		return "<tr>"+
		"<td>胜率：</td>"+
		"<td><input class='form-control shenglv' value='" + shenglv + "' /></td>"+
		"<td>推荐费率：</td>"+
		"<td><div style='display:flex;align-items:center;'><input class='form-control tuijian' /> 倍</div></td>"+
	"</tr>"	
	} */
/* 	
	var VALUE_OBJ = {
			"3": {col: 2, valueArr: [0.5, 1],},
			"5": {col: 3, valueArr: [0.5, 0.75, 1],},
			"7": {col: 4, valueArr: [0.5, 0.66, 0.83, 1],},
	}
	
	function createShengLvAndTuiJian(value) {
		var $tbody = $(".table-c-ShengLvAndTuiJianList tbody")
		  $tbody.html("")
		  var dataOBJ = VALUE_OBJ[value]
		  for (var i = 0; i < dataOBJ.col; i++) {
			  $tbody.append(shengLvItem(dataOBJ.valueArr[i])) 
		  }		
	}
	
	$('#addModal').on('show.bs.modal', function () {
		createShengLvAndTuiJian($("#select-i-chooseDayNum").val())
	})
	$("#select-i-chooseDayNum").on("change", function(e) {
		createShengLvAndTuiJian($(e.currentTarget).val())
	}) */
		$.ajax({
			url: "/czgl/gendanlvall.do",
			type: "POST",
			data: {},
			success: function(json) {
				$("[data-rebate]").each(function(index, element) {
					element.value = json.data["rebate" + element.dataset.rebate]
				})
				$("#select-i-chooseDayNum").val(json.data.severalTime)
			},
			error: function(error) {
				showNoticeModal("网络繁忙")
			}
		})
		$("#select-i-chooseDayNum").on("change", function(e) {
			$.ajax({
				url: "/czgl/gendanlvall.do",
				type: "POST",
				data: {
					severalTimes:$("#select-i-chooseDayNum").val(),
				},
				success: function(json) {
					$("[data-rebate]").each(function(index, element) {
						element.value = json.data["rebate" + element.dataset.rebate]
					})
				},
				error: function(error) {
					showNoticeModal("网络繁忙")
				}
			})			
		})
		var doubleNumberReg = /^[0-9]+([.]{1}[0-9]{1,2})?$/
		$("#button-i-addNewZongDaiLi").on("click", function(e) {
			var allRebates = $("[data-rebate]")
			var request = {
				url: "/czgl/gendanlvadd.do",
				type: "POST",
				data: {
					severalTime: $("#select-i-chooseDayNum").val()
				},
				success: function(json) {
					showNoticeModal("保存成功！")
				},
				error: function(error) {
					showNoticeModal("网络繁忙")
				}
			}
			var flag = true
			for (var i = 0; i < allRebates.length; i++) {
				var item = allRebates[i]
				if (!doubleNumberReg.test(item.value) || Number(item.value) > 1) {
					showNoticeModal("推荐费率有误，请重新填写")
					flag = false
					break
				}
				request.data["rebate" + item.dataset.rebate] = item.value
			}
			if (!flag) {
				return
			}
			$.ajax(request)			
		})
	/* 	$("#table-i-gendanControlList").on("click", ".btn-c-editGenDanInfo", function(event) {
			$("#addAndEditModal").attr("data-type", "edit")
			var $parentTr = $(event.target).closest("tr")
			$("#editModal .input-auto").each(function(index, element) {
				$(element).val($parentTr.find("." + element.id.split("-")[2] + "-edit-td").text())
			})
			$("#editModal").modal("show")
		})
		$("#table-i-gendanControlList").on("click", ".btn-c-delGenDanInfo", function(event) {
			$("#deleteModal").attr("data-id", $(event.currentTarget).closest("tr").find(".id-edit-td").text())
			$("#deleteModal").modal("show")
		})		
		$('#addAndEditModal').on('hidden.bs.modal', function () {
			if ($("#addAndEditModal").attr("data-type") == "edit") {
				$("#addAndEditModal form")[0].reset()
			}
		})
		$("#button-i-addShengLv").on("click", function(e) {
			var objArr = []
			var allTrs = $(".table-c-ShengLvAndTuiJianList").find("tr")
			var isFloatNum = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/
			var flag = true
			var shenglvsValue = ""
			var rebatesValue = ""
			for (var z = 0; z < allTrs.length; z++) {
				var item = allTrs[z]
				var shenglvValue = item.querySelector(".shenglv").value
				if (shenglvValue == "" || !isFloatNum.test(shenglvValue)) {
					showNoticeModal("胜率输入有误")
					flag = false
					break
				}
				var tuijianValue = item.querySelector(".tuijian").value
				if (tuijianValue == "" || !isFloatNum.test(tuijianValue) || Number(tuijianValue) > 1) {
					showNoticeModal("推荐费率输入有误")
					flag = false
					break
				}
				shenglvsValue += shenglvValue + ","
				rebatesValue += tuijianValue + ","
			}
			if (!flag) {
				return
			}
			$.ajax({
				url: "gendanlvadd.do",
				type: "POST",
				data: {
					shenglvs: shenglvsValue,
					rebates: rebatesValue,
					count: $("#select-i-chooseDayNum").val(),
				},
			}).then(function(data) {
				showNoticeModal("新增成功！")
				$("#addModal").modal("hide")
				$("#table-i-gendanControlList").DataTable().ajax.reload()
			}, function(error) {
				
			})
		}) */
	</script>
</body>
</html>